<template>
  <div>
    <el-form inline :model="queryData" ref="queryData" class="query-form">
      <el-form-item label="公司名称:" prop="name">
        <el-input v-model="queryData.name" placeholder="请输入" style="width: 200px" clearable @clear="formClear('name')"/>
      </el-form-item>

      <el-form-item label="联系电话:" prop="phone">
        <el-input v-model="queryData.phone" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('phone')"/>
      </el-form-item>

      <el-form-item label="项目名称:" prop="itemName">
        <el-input v-model="queryData.itemName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('itemName')"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">查 询</el-button>
        <el-button @click="onReset">重 置</el-button>
        <el-button type="warning" @click="onExport">导 出</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableList" border style="width: 100%;">
      <el-table-column prop="id" label="ID" align="center" width="80"/>
      <el-table-column prop="name" label="姓名" align="center" width="150"/>
      <el-table-column prop="phone" label="联系电话" align="center"/>
      <el-table-column prop="address" label="联系地址" align="center" show-overflow-tooltip/>
      <el-table-column prop="itemName" label="项目名称" align="center"/>
      <el-table-column prop="itemIntroduce" label="项目介绍" align="center" show-overflow-tooltip/>
      <el-table-column prop="createTime" label="创建时间" align="center" width="150"/>
      <el-table-column label="操作" align="center" width="100" fixed="right">
        <template slot-scope="{row}">
          <el-button type="text" @click="deleteEvent(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Paging v-model="queryData" @change="getRequest"></Paging>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
import request from '@/utils/request'
export default {
  computed: {
    ...mapGetters(['confirm'])
  },
  name: 'enterpriseAttract',
  data() {
    return {
      tableList: [],
      queryData: {
        address: null, // 联系地址
        itemName: null, // 项目名称
        name: null, // 姓名
        phone: null, // 联系电话
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      entity: null,
      drawer: false
    }
  },
  beforeMount() {
    this.getRequest()
  },
  // /enterprise/serveSubmitPutin/export
  methods: {
    onExport() {
      this.$confirm("是否确认导出所有数据?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => request.get('/enterprise/serveSubmitPutin/export')).then((response) => {
        this.download(response.data);
      })
    },
    deleteEvent(row) {
      this.$confirm(this.confirm.text, '提示', this.confirm.options).then(async () => {
        await this.$ajax.get(`/enterprise/serveSubmitPutin/remove?ids=${row.id}`)
        this.$message.success('操作成功')
        this.onSubmit()
      })
    },
    /**
     * 重置事件
     */
    onReset() {
      this.queryData.pageNum = 1
      this.queryData.province = null
      this.queryData.city = null
      this.queryData.county = null
      this.$refs['queryData'].resetFields()
      this.getRequest()
    },
    /**
     * 查询条件提交事件
     */
    onSubmit() {
      this.queryData.pageNum = 1
      this.getRequest()
    },
    /**
     * 列表请求事件
     */
    async getRequest() {
      const params = JSON.parse(JSON.stringify(this.queryData))
      const res = await this.$ajax.get('/enterprise/serveSubmitPutin/list', {params})
      this.queryData.total = res.total
      this.tableList = res.rows
    },
    /**
     * form-input 置空事件
     */
    formClear(key) {
      this.queryData[key] = null
      this.onSubmit()
    }
  }
}
</script>

<style scoped>

</style>
